package com.lh.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lh.commonutils.R;
import com.lh.entity.EduCourse;
import com.lh.entity.EduTeacher;
import com.lh.service.IEduCourseService;
import com.lh.service.IEduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//@CrossOrigin
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private IEduCourseService courseService;

    @Autowired
    private IEduTeacherService teacherService;

//   查询前八条热门课程  前四条讲师
    @GetMapping("index")
    public  R  index(){
//        查询前八个热门课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> eduCourseListlist = courseService.list(wrapper);

        //        查询前四条讲师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit  4");
        List<EduTeacher> eduTeacherList = teacherService.list(teacherQueryWrapper);


        return R.ok().data("eduList",eduCourseListlist).data("teacherList",eduTeacherList);
    }

}



